from rest_framework import serializers

from cate.models import Cate


class CateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cate
        fields = '__all__'

    def create(self, validated_data):
        return Cate.objects.create(**validated_data)

    def update(self, instance, validated_data):
        instance.cate_name = validated_data.get('cate_name', instance.cate_name)
        instance.cate_alias = validated_data.get('cate_alias', instance.cate_alias)
        instance.save()
        return instance